<template>
  <div class="pakpay">
    <div class="pakpay-form">
      <el-form
        label-position="right"
        label-width="100px"
        style="display: flex; flex-wrap: wrap; gap: 20px"
      >
        <el-form-item >
          <el-input placeholder="反馈人" v-model="form.username"></el-input>
        </el-form-item>

        <el-form-item >
          <el-input
            placeholder="请输入反馈内容"
            v-model="form.feedtext"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-date-picker
            v-model="form.startDate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始反馈日期"
            end-placeholder="结束反馈日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getTableData">
            <i class="el-icon-search"></i>搜索
          </el-button>
          <el-button type="warning" @click="resetForm()">
            <i class="el-icon-edit"></i>重置
          </el-button>
        
        </el-form-item>
      </el-form>
    </div>
    <div class="pakpay-table">
      <el-table :data="tableData" border style="width: 100%">
        <!-- 序号 -->
        
        <el-table-column prop="title" label="反馈人" width="200">
        </el-table-column>
        <el-table-column prop="content" label="反馈内容" width="200">
        </el-table-column>
        <el-table-column prop="createtime" label="反馈时间" width="200">
        </el-table-column>
        <el-table-column prop="communityname" label="服务内容" width="170">
        </el-table-column>
        <el-table-column prop="communityname" label="处理状态" width="170">
        </el-table-column>
        <el-table-column prop="communityname" label="服务评分" width="170">
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.row)"
              type="danger"
              size="small"
              ><i class="el-icon-delete"></i>归档</el-button
            >
            <el-button
              size="small"
              type="primary"
              @click="handleDetail(scope.row)"
              ><i class="el-icon-zoom-in"></i>查看公告</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 通知缴费详情 -->
    <el-dialog
      title="车位订单详情"
      :visible.sync="dialogVisible1"
      width="50%"
      :before-close="handleClose"
    >
      <el-form
        :model="handselect"
        ref="ruleForm"
        label-width="80px"
        class="demo-ruleForm"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="小区名称" prop="communityname">
              <el-input readonly v-model="handselect.communityname"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布时间">
              <el-date-picker
                v-model="handselect.createtime"
                readonly
                type="date"
                placeholder="发布时间"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="公告主题" prop="title">
          <el-input readonly v-model="handselect.title"></el-input>
        </el-form-item>
        <el-form-item prop="orderstatus" label="公告内容" width="200">
          <el-input readonly v-model="handselect.content"> </el-input>
        </el-form-item>

        <el-form-item label="公告状态" disabled prop="parkpayNotify">
          <el-button disabled>阅读量</el-button>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">关闭</el-button>
      </span>
    </el-dialog>

    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: true,
      total: 0,
      form: {
        username: "",
        feedtext: "",
        startDate: "",
        endDate: "",
        feedresult: "",
        feedstatus: "",
        currPage: 0,
        pageNum: 10,
      },
      dialogVisible1: false,
      tableData: [],
      handselect: {},
      tableData1: "",
    };
  },
  methods: {
    // 添加公告
    async addreset() {
      try {
        const { data: res } = await this.axios.post(
          `poster/addPoster?communityname=${this.form.communityname}&title=${
            this.form.title
          }&content=${this.form.content}&token=${sessionStorage.getItem(
            "token"
          )}`,
          {
            communityname: this.form.communityname,
            title: this.form.title,
            content: this.form.content,
            token: sessionStorage.getItem("token"),
          }
        );
        this.form.title = "";
        this.form.communityname = "";
        this.form.content = "";
        if (res == "发布成功") {
          this.$message.success("添加成功");
          this.getTableData();
        } else {
          this.$message.error("添加失败");
        }
      } catch (error) {
        this.handleError("添加失败", error);
      }
    },
    handleSizeChange(val) {
      this.form.pageNum = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.form.currPage = val - 1;
      this.getTableData();
    },
    handleDetail(val) {
      this.dialogVisible1 = true;
      this.handselect = val;
      console.log(val);
    },
    reset() {
      (this.tableData1.startdate = ""),
        (this.tableData1.enddate = ""),
        (this.tableData1.note = ""),
        (this.tableData1.orderstatus = ""),
        (this.tableData1.orderpay = ""),
        this.getTableData();
    },
    handleClick(val) {
      console.log(val);

      this.$confirm("确定永久归档这条公告?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            const response = await this.axios.get(
              `poster/delPoster?p_id=${val.p_id}&token=${sessionStorage.token}`
            ); // 使用val.id作为参数p_
            this.$message({
              type: "success",
              message: "归档公告成功!",
            });
            this.getTableData();
            console.log(response.data); // 输出删除接口的响应
          } catch (error) {
            this.$message({
              type: "error",
              message: "归档公告失败!",
            });
            console.error(error);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消归档公告",
          });
        });
    },
    // 通知缴费弹窗
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done(); // 确认时执行的操作
        })
        .catch(() => {
          done(); // 取消时执行的操作
        });
    },
    async getTableData() {
      try {
        const { data: res } = await this.axios.get("poster/getFeedBack?", {
          params: this.form,
        });
        console.log(res);
        this.tableData = res.data;
        this.total = res.total;
      } catch (error) {
        this.handleError("获取数据失败", error);
      }
    },
    resetForm() {
      this.form = {
        username: "",
        feedtext: "",
        startDate: "",
        endDate: "",
        feedresult: "",
        feedstatus: "",
        pageNum: 10,
        currPage: 0,
      };
    },
    // 导出excel
    async fimalyExcel() {
      try {
        const { data: res } = await this.axios.get("poster/getFeedBack", {
          params: this.form, // 使用 params 将表单数据作为查询字符串
          responseType: "blob", // 设置响应类型为 blob
        });

        // 处理文件下载
        const url = URL.createObjectURL(new Blob([res]));
        const link = document.createElement("a");
        link.href = url;
        link.setAttribute("download", "样本审核数据.xlsx"); // 文件名
        document.body.appendChild(link);
        link.click();
        link.remove();

        this.$message.success("导出成功！");
      } catch (error) {
        console.error(error);
        this.$message.error("导出失败: " + error.message);
      }
    },
  },
  created() {
    this.getTableData();
  },
};
</script>

<style lang="scss" scoped>
.block {
  text-align: right;
  margin-bottom: 20px;
}
.pakpay {
  margin: 1.3% 1%;
  padding: 0 0;
  background-color: #fff;
  height: calc(100% - 46px);
  display: flex;
  flex-direction: column;

  .pakpay-form {
    padding: 20px;

    .el-form-item {
      margin-bottom: 0; // 调整表单项之间的间距
    }
  }

  .pakpay-table {
    flex: 2;
    padding: 20px;
  }
}
.el-col-8 {
  width: 335px;
}
::v-deep .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  border-bottom: 1px solid #ebeef5;
  text-align: center;
}
::v-deep th.el-table__cell.is-leaf {
  border-bottom: 1px solid #ebeef5;
  text-align: center;
}
::v-deep .el-table .el-table__cell {
  padding: 5px 0;
}
</style>